@extends('host.common.store.common')
@section('content')
    <div class="homepage-m-r">
        <div class="m-r-title">
            <div class="f16 ml10 lh40">推荐商品</div>
        </div>
        <div class="m-r-box clearfix">
            @foreach ( \App\B2BProject\Custom\Business\Goods::where('store_id',$storeInfo->id)->HasCover()->where('recommend_status','1')->where('strict_lock',false)->orderBy('created_at', 'desc')->take(10)->get() as $good)
                <div class="common-box4 m-r-b">
                    <div class="box4-img">
                        <a href="{{route('goods.detail',[$good->id])}}">
                            <img src="{{$good->cover()}}"></a>
                    </div>
                    <div class="box4-text">
                        <a href="{{route('goods.detail',["$good->id"])}}" title="{{$good->name}}">{{$good->name}}</a>
                    </div>
                    <div class="box4-text-left">
                        <?php
                        if (\Auth::check()) { //  已登陆状态
                            if ($good->grant_status == '0') {     //判断是否是自由集散区的商品
                                echo $good->original_price;
                            } else {
                                if (\Auth::user()->class == 2) {  // 采购商身份
                                    if ($good->isGranted()) {//判断是否授权
                                        echo '￥' . $good->original_price ;
                                    } else {
                                        echo '未授权';
                                    }
                                } else {  //供应商身份
                                    $member = \Auth::user();
                                    if (\App\B2BProject\Custom\Business\Goods::where('store_id',
                                            \App\B2BProject\Custom\Business\Store::where('member_id',
                                                    $member->id)->first()->id)->first()
                                    ) {   // 供应商有自己的店铺
                                        if (\App\B2BProject\Custom\Business\Goods::where('store_id',
                                                        \App\B2BProject\Custom\Business\Store::where('member_id',
                                                                $member->id)->first()->id)->first()->store_id == $storeInfo->id
                                        ) { //供应商自己的店铺
                                            echo '￥' . $good->original_price;
                                        } else {
                                            echo '未授权';
                                        }
                                    } else {
                                        echo '未授权';
                                    }
                                }
                            }
                        }  else {//未登陆状态
                            if ($good->grant_status == '0') {     //判断是否是自由集散区的商品
                               echo $good->original_price;
                            } else {
                                echo "请登录后查看";
                            }
                        }
                        ?>
                    </div>
                    <div class="box4-text-right">{{$good->minimum_order}}起订</div>
                </div>
            @endforeach
        </div>
    </div>
    <div class="homepage-m-r homepage-m-r2">
        <div class="m-r-title">
            <div class="f16 ml10 lh40">全部商品</div>
        </div>
        <div class="m-r-box clearfix">
            @if(!empty($categorydata))
                <?php $goods =
                        \App\B2BProject\Custom\Business\Goods::where('store_id', $storeInfo->id)->where('strict_lock',false)->where('category_id',
                                $categorydata)->HasCover()->orderBy('created_at', 'desc')->take(10)->get(); ?>
            @else
                <?php $goods = \App\B2BProject\Custom\Business\Goods::where('store_id',
                        $storeInfo->id)->HasCover()->where('strict_lock',false)->orderBy('created_at', 'desc')->take(10)->get(); ?>
            @endif

            @foreach ($goods as $good)
                <div class="common-box4 m-r-b">

                    <div class="box4-img">
                        <a href="{{route('goods.detail',["$good->id"])}}">
                            <img src="{{$good->cover()}}"></a>
                    </div>
                    <div class="box4-text">
                        <a href="{{route('goods.detail',["$good->id"])}}" title="{{$good->name}}">{{$good->name}}</a>
                    </div>
                    <div class="box4-text-left">
                        <?php
                        if (\Auth::check()) { //  已登陆状态
                            if ($good->grant_status == '0') {     //判断是否是自由集散区的商品
                                echo $good->original_price;
                            } else {
                                if (\Auth::user()->class == 2) {  // 采购商身份
                                    if ($good->isGranted()) {//判断是否授权
                                        echo '￥' . $good->original_price;
                                    } else {
                                        echo '未授权';
                                    }
                                } else {  //供应商身份
                                    $member = \Auth::user();
                                    if (\App\B2BProject\Custom\Business\Goods::where('store_id',
                                            \App\B2BProject\Custom\Business\Store::where('member_id',
                                                    $member->id)->first()->id)->first()
                                    ) {   // 供应商有自己的店铺
                                        if (\App\B2BProject\Custom\Business\Goods::where('store_id',
                                                        \App\B2BProject\Custom\Business\Store::where('member_id',
                                                                $member->id)->first()->id)->first()->store_id == $storeInfo->id
                                        ) { //供应商自己的店铺
                                            echo '￥' . $good->original_price;
                                        } else {
                                            echo '未授权';
                                        }
                                    } else {
                                        echo '未授权';
                                    }
                                }
                            }
                        }  else {//未登陆状态
                            if ($good->grant_status == '0') {     //判断是否是自由集散区的商品
                               echo  $good->original_price;
                            } else {
                                echo "请登录后查看";
                            }
                        }
                        ?>
                    </div>
                    <div class="box4-text-right">{{$good->minimum_order}}起订</div>

                </div>
            @endforeach

        </div>
    </div>

@stop